import { Component, OnInit } from '@angular/core';
import { MAIN_STAT } from 'src/app/service/action_type';
import { ArticleService } from 'src/app/service/article.service';
import { CustomService } from 'src/app/service/custom.service';
import { LivelibService } from 'src/app/service/livelib.service';
import { RequestService } from 'src/app/service/request.service';

@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.less']
})
export class IndexComponent implements OnInit {

  data: any = {};
  securityGrade: string = '中等';
  securityScore: number = 30;
  articleList1: any[] | null;
  articleList2: any[] | null;
  articleList3: any[] | null;
  isDetailShow: boolean = false;
  articleType: string | null;
  article: any = {};
  statData: any = {};

  close() {
    this.isDetailShow = false;
  }

  showDetail(type: string, no: number) {
    this.articleType = type;
    switch (type) {
      case '更新日志':
        this.article = this.articleList1[no];
        break;
      case '新手入门':
        this.article = this.articleList2[no];
        break;
      case '平台资讯':
        this.article = this.articleList3[no];
        break;
    }
    this.isDetailShow = true;
  }

  constructor(
    private customService: CustomService,
    private articleService: ArticleService,
    private requestService: RequestService
  ) { }

  ngOnInit(): void {
    this.customService.profile().subscribe(result => {
      this.data = result['data'];
      this.securityScore = 30;
      if (this.data['isEmailAuth'])
        this.securityScore += 23;
      if (this.data['isPhoneAuth'])
        this.securityScore += 23;
      if (this.data['authentication'] === 100)
        this.securityScore += 24;
      if (this.securityScore >= 100)
        this.securityGrade = '高级';
      else if (this.securityScore >= 75)
        this.securityGrade = '较高';
      else if (this.securityScore >= 53)
        this.securityGrade = '中等';
      else
        this.securityGrade = '较低';
    });
    this.articleService.getTop('更新日志').subscribe(result => {
      this.articleList1 = result['data'];
    });
    this.articleService.getTop('新手入门').subscribe(result => {
      this.articleList2 = result['data'];
    });
    this.articleService.getTop('紧急通知').subscribe(result => {
      this.articleList3 = result['data'];
    });
    this.requestService.get(MAIN_STAT).subscribe(result => {
      this.statData = result['data']
    });
  }

}
